﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseData.UI;
using System.Xml;

namespace Admin.SysConfig
{
    public partial class AuthPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string action = PageContext.GetRequest("action");
            if (!string.IsNullOrEmpty(action))
            {
                this.DoAction(action);
            }
        }

        protected void DoAction(string action)
        {
            try
            {
                string autString = PageContext.GetRequest("txtAuth");
                if (!string.IsNullOrEmpty(autString))
                {
                    //修改web.config
                    string filePath = Server.MapPath("\\Admin\\web.config");
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(filePath);
                    string xPath = "/configuration/appSettings/add[@key='EncyTips']";
                    XmlNode addKey = xmlDoc.SelectSingleNode(xPath);
                    if (addKey != null)
                    {
                        addKey.Attributes["value"].InnerText = autString;
                    }
                    xmlDoc.Save(filePath);
                }
                Jscript.AlertAndRedirect("授权成功，请打开其他页面测试", "AuthPage.aspx");
            }
            catch
            {
                Jscript.AlertAndRedirect("授权失败", "AuthPage.aspx");
            }
        }
    }
}